﻿using Hiver.Util.Config;
using Hiver.Util.Config.Model;
using MongoDB.Driver;

namespace Hiver.Util.MongoDB
{
    /// <summary>
    /// MongoDB帮助类
    /// </summary>
    public static class MongoHelper
    {
        /// <summary>
        /// 获得数据库集合
        /// </summary>
        /// <returns></returns>
        public static IMongoDatabase GetDatabase()
        {
            ApplicationConfigModel config = YamlHelper<ApplicationConfigModel>.Load();
            if (config == null)
                Error.Show(1);
            if (config.Mongo == null || config.Mongo.Count <= 0)
                Error.Show(3);
            MongoClient client = new MongoClient(config.Mongo[0].ConnectionString);
            return client.GetDatabase(config.Mongo[0].Database);
        }
    }
}